<template>
  <div class="app-container">
    <div class="container">
      <div>
        <div class="radio-label">入库规则</div>
        <el-radio-group v-model="inStorageRule"  @change="handleSaveInStorageRule"  >
          <el-radio label="1" >按库存物料所在库位</el-radio>
          <el-radio label="2" >就近库位推荐（库位编号排序）</el-radio>
          <el-radio label="3" >按指定库位</el-radio>
        </el-radio-group>
      </div>
      <hr>
      <div>
        <div class="radio-label">出库规则</div>
        <el-radio-group v-model="outStorageRule" @change="handleSaveOutStorageRule"  >
          <el-radio label="1"  > 先进先出</el-radio>
          <el-radio label="2" >后进先出</el-radio>
        </el-radio-group>
      </div>
      <hr>
        </div>
      <!--<div class="btn-group">-->
        <!--<el-button type="primary" @click="save">保存</el-button>-->
        <!--<el-button @click="cancel">取消</el-button>-->
      <!--</div>-->

  </div>
</template>

<script>

  import { getConfigKey, updateConfig } from "@/api/system/config";
export default {
  name: "tactic",
  data() {
    return {
      //选择数据
      inStorageRule: '3',
      outStorageRule: '1',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 库存占用明细表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        no: null,
        stockOccupyNo: null,
        storehouseLocationNo: null,
        barcode: null,
        productNo: null,
        occupyQty: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        no: [
          { required: true, message: "编号不能为空", trigger: "blur" }
        ],
        delFlag: [
          { required: true, message: "是否删除：1是 0否不能为空", trigger: "blur" }
        ],
      },
      // 订单信息
      orderInfo:{
        no : null
      }
    };
  },
  created() {
    this.getInStorageRule();
    this.getOutStorageRule();
  },
  watch: {

  },
  methods: {
    getInStorageRule(){
      const key = 'tactic.instorage';
      getConfigKey(key).then(res => {
        this.inStorageRule = res.msg;
      });
    },
    getOutStorageRule(){
      const key = 'tactic.outstorage';
      getConfigKey(key).then(res => {
        this.outStorageRule = res.msg;
      });
    },

    /** 修改入库规则 */
    handleSaveInStorageRule() {
      this.$modal.confirm('是否确认修改入库规则?').then(()=>{
        updateConfig({
          configKey:"tactic.instorage",
          configValue:this.inStorageRule
        }).then(res => {
          this.$modal.msgSuccess("修改入库规则成功");
          this.getInStorageRule();
        })
      }).then(() => {
      }).catch(() => {});
    },
    /** 修改出库规则 */
    handleSaveOutStorageRule() {
      this.$modal.confirm('是否确认修改出库规则?').then(()=>{
        updateConfig({
          configKey:"tactic.outstorage",
          configValue:this.outStorageRule
        }).then(res => {
          this.$modal.msgSuccess("修改出库规则成功");
          this.getOutStorageRule();
        });
      }).then(() => {
      }).catch(() => {});
    },


    getList() {

    },
    save() {
      // TODO: 保存操作
      console.log('保存选项：', this.selectedOption)
    },
    // 取消按钮
    cancel() {
      // TODO: 取消操作
      window.location.reload();
      console.log('取消选项：', this.selectedOption)
    }
  }
};
</script>

<style scoped>
.container {
  padding: 20px;
  border-radius: 5px;
}
.radio-group {
  display: flex;
  flex-direction: column;
}

.radio-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.radio-label {
  margin-left: 10px;
}

.btn-group {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}

.el-radio-group {
  padding: 20px;
}
</style>
